<template>
  <div class="login">
    <div class="login-box">
      <h2 class="title">修改密码</h2>
      <el-form :model="form" :rules="rules" ref="form" label-width="0px" class="ms-content">
        <el-form-item prop="password">
          <el-input placeholder="6-16位密码，区分大小写" v-model="form.password" @keyup.enter.native="submitForm()"></el-input>
        </el-form-item>
        <el-form-item prop="verifypassword">
          <el-input placeholder="请再次输入密码" v-model="form.verifypassword" @keyup.enter.native="submitForm()">
          </el-input>
        </el-form-item>
        <div class="password-setting">
          <div @click="$router.push('/login')">去登录</div>
        </div>
        <el-form-item class="login-btn">
          <el-button type="primary" @click="submitForm()">确 定</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
  import apis from '../apis/modules/login'
  export default {
    data() {
      var validatePassword = (rule, value, callback) => {
        if (value != this.form.password) {
          callback(new Error("与新密码不一致!"));
        } else {
          callback();
        }
      };
      return {
        form: {
          password: '',
          verifypassword: ''
        },
        rules: {
          password: [{ required: true, message: '请输入新密码', trigger: 'blur' }],
          verifypassword: [
            { required: true, message: '请确认密码', },
            { validator: validatePassword, trigger: 'blur' }
          ],
        }
      }
    }, methods: {
      // 确认修改
      submitForm() {
        this.$refs.form.validate(async valid => {
          if (valid) {
            const { code, data, msg } = await apis.modifyPassword({
              password: this.form.password
            })
            if (code == 200) {
              this.$message.success(msg)
              this.$router.push('/Login')
            } else {
              this.$message.error(msg)

            }
          }
        })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .handle-search {
    width: 240px;
    height: 40px;
    margin-right: 15px;
  }

  .login {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url(../assets/img/bg.jpg);
  }

  .login-box {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 574px;
    height: 428px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;


    .title {
      margin: 40px 0;


    }

    .ms-content {
      width: 368px;

      .password-setting {
        display: flex;
        justify-content: flex-end;

        color: #1890FF;
        font-size: 13px;
        cursor: pointer;

      }

      .login-btn button {
        margin-top: 60px;
        width: 100%;
      }

      .login-tips {
        text-align: center;
        color: #333;
        font-size: 13px;
      }
    }
  }
</style>